package com.itheima.reggie.mapper;

import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface SetmealMapper {


    //根据类别的id查找套餐总数
    @Select("select count(*) from setmeal where category_id=#{id}")
    long findSetMealWithCategory(Long id);

    @Insert("INSERT INTO setmeal VALUES (null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void saveWithDish(SetmealDto setmealDto);

    /**
     * 根据名字模糊查询查找套餐
     *
     * @param name
     * @return
     */
    List<Setmeal> findByName(String name);

    /**
     * 作用: 查询套餐状态集合中状态(status)为0的数量,若大于0则里面有不能删除的套餐
     *
     * @param ids 套餐id集合
     * @return
     */
    Long queryDishWithStatus(@Param("ids") List<Long> ids);

    /**
     * 作用: 根据套餐的id删除套餐
     *
     * @param ids
     */
    void deleteById(@Param("ids") List<Long> ids);

    /**
     * 根据Id查找套餐
     *
     * @param id
     * @return
     */
    @Select("SELECT *FROM setmeal WHERE id=#{id}")
    Setmeal findById(Long id);

    /**
     * 作用;添加菜品套餐
     *
     * @param setmealDto 页面传递过来套餐和菜品
     * @param
     * @return
     */
    void updateById(SetmealDto setmealDto);

    /**
     * 启/停售 (可批量)
     * @param ids
     * @param status
     * @return
     */
    void updateStatus(@Param("ids") List<Long> ids, @Param("status") Integer status);
}
